Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($location): path to work with full url #8924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gauravaror
Copy link

Changed the way $location.path is handled. Now path function will check if the path contain the base url (protocol://host) is this is there in the path. Mostly user has passed the full url instead of path.
We process it differently, by calling the parse method of the respective location object. Since parse method takes care if the url is HTML5 mode , HTML5 hashbang mode or non HTML5 urls and parses them respectively.

Currently i have made directly used the parse function which updates the whole location object. We can also ass a parsePath method to each of LocationHashbangInHtml5Url,LocationHashbangUrl, LocationHtml5Url classes which will copy implementation from parse method and get the path out of newUrl but won't update the location object. If this implementation have some issue i can work on making this change.

Closes #8617

@caitp
Copy link
Contributor

caitp commented Sep 4, 2014

What is the use case really? It seems kind of bad because the hostname/protocol shouldn't be an important part of the app (it's really just a deployment detail). Just my opinion though :>

@caitp caitp added this to the Backlog milestone Sep 4, 2014
@WhatFreshHellIsThis
Copy link

@caitp See the referenced case for the use case, where you commented on this same issue previously.

@caitp
Copy link
Contributor

caitp commented Sep 4, 2014

It's a common use case in an application to prompt the user when a route change is detected with the current page editing a dirty record.

This isn't a real use case though, the current design doesn't prevent this from happening. No use case is provided for changing the app location using the full URL

@WhatFreshHellIsThis
Copy link

I can assure you it's a real (and real common) use case. I must be missing something. You seemed to agree with this before, now you seem to disagree. What am I missing?

It's a fact that the very url the event provides is not usable to continue navigation so there's a fundamental issue here no matter the use case.

@caitp
Copy link
Contributor

caitp commented Sep 4, 2014

I never said I agree that it's a good use case, I said it's kind of annoying that we don't let you set an absolute URL --- but there are good reasons for this. Anyways, the decision on whether to include this in the framework isn't up to me really, however I can think of good reasons why we wouldn't want to support that.

@WhatFreshHellIsThis
Copy link

Interesting, I feel that you might not fully understand what is going on here or have a skewed view of it that I can't quite fathom.

I view it as a straightforward inconsistency and design mistake in implementing the API, but I have a workaround and more pressing issues to attend to, so I'll leave it to the collective wisdom of the crowd.

@caitp
Copy link
Contributor

caitp commented Sep 4, 2014

I feel that you might not fully understand what is going on here or have a skewed view of it that I can't quite fathom.

I assure you, I understand what you're trying to do --- but one should not be specifying full urls here, it just doesn't make any sense (in my opinion). There are other workarounds, like replacing the application base url with the empty string in the event handler.

I think that is probably a much better (safer) solution to this problem than what is implemented currently in this PR.

@gauravaror
Copy link
Author

@caitp hostname and protocol is used :

  1. Only to ensure that we change path for the full URL which pertains to the current app.
  2. We don't replace code path for the normal "/user/app" cases.

Why i am not checking if this is just the full path with hostname ?
Since path function is used to navigate inside the same website. So i only want to address the full paths within the same application. the hostname is identification of location not going outside the app and can be handeled by the $location.path(). hence used to identify the cases we can handle in this way.

It will be good to navigate using the full url in the $location.path().

@gauravaror
Copy link
Author

@caitp You mentioned other work around will be to replace the application base url with empty string. are you mentioning to event handler for the event locationChangeStart.

sorry i am quite new to angular if i am missing something. in solution you proposed

Just to understand the solution, we only have access to event object, newUrl and oldUrl.

are you proposing to create a new Location object and pass the empty string in appBaseUrl and then use $location.$$parse to get the path in event handler. but how this will navigate to the correct location since parse use the appBase url to get path . As we are setting it to empty string it won't be able to get the correct parsing as i see in the code.

There is some method in event object and it does the parsing properly.
I guess if we have to get the path out of the full url we need to have the correct application base url . i don't seem to understand how we will get the application path from full url by making application base url as empty.

Thanks for commenting and reviewing the PR 👍

@gauravaror gauravaror force-pushed the locationchangeStartURL branch from 2eeea57 to 51c198a Compare September 5, 2014 08:08
@caitp
Copy link
Contributor

caitp commented Sep 5, 2014

I'm saying the path() routine could replace the appBase with the empty string, if found --- because that is the only full url that should ever be used

Changed the way $location.path is handled. Now path function will check if the path contain the base url (protocol://host) is this is there in the path. Mostly user has passed the full url instead of path.
We process it differently, by calling the parse method of the respective location object. Since parse method takes care if the url is HTML5 mode , HTML5 hashbang mode or non HTML5 urls and parses them respectively.

Currently i have made directly used the parse function which updates the whole location object. We can also ass a parsePath method to each of  LocationHashbangInHtml5Url,LocationHashbangUrl,  LocationHtml5Url classes which will copy implementation from parse method and get the path out of newUrl but won't update the location object. If this implementation have some issue i can work on making this change.

Closes angular#8617
@gauravaror gauravaror force-pushed the locationchangeStartURL branch from fc9976d to 0b85ae0 Compare September 16, 2014 13:34
@jeffbcross jeffbcross force-pushed the master branch 2 times, most recently from cad9560 to f294244 Compare October 2, 2014 22:09
@jeffbcross jeffbcross force-pushed the master branch 4 times, most recently from e8dc429 to e83fab9 Compare October 10, 2014 17:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$locationChangeStart: difficult to preventDefault then allow via $location.path(newurl)
4 participants